﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Enterprise.Model.Module;
using Enterprise.Service.Module;
using Enterprise.Infrastructure;
namespace Enterprise.UI.Web.Manage.Module
{
    public partial class Edit : System.Web.UI.Page
    {
        int Id = (int)Utility.sink("Id", Utility.MethodType.Get, 0, 0, Utility.DataType.Int);
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                OnStart();
            }
        }

        private void OnStart()
        {
            OnBindData();
        }

        private void OnBindData()
        {
            ModuleService ser = new ModuleService();
            var q = ser.ModuleDisp(Id);
            if (q != null)
            {
                mCode.Text = q.MCODE;
                mName.Text = q.MNAME;
                mUrl.Text = q.MURL;
                ListItem lis = mSingle.Items.FindByValue(q.MSINGLE.ToString());
                if (lis != null)
                {
                    lis.Selected = true;
                }
                ListItem li = mTarget.Items.FindByValue(q.MTARGET);
                if (li != null)
                {
                    li.Selected = true;
                }
            }
        }


        protected void Button1_OnClick(object sender, EventArgs e)
        {
            ModuleService ser = new ModuleService();
            var m = ser.ModuleDisp(Id);
            if (m != null)
            {
                m.MCODE = (string)Utility.sink(mCode.UniqueID, Utility.MethodType.Post, 0, 0, Utility.DataType.Str);
                m.MNAME = (string)Utility.sink(mName.UniqueID, Utility.MethodType.Post, 0, 0, Utility.DataType.Str);
                m.MURL = (string)Utility.sink(mUrl.UniqueID, Utility.MethodType.Post, 0, 0, Utility.DataType.Str);
                m.MSINGLE = (int)Utility.sink(mSingle.UniqueID, Utility.MethodType.Post, 0, 0, Utility.DataType.Int);
                m.MTARGET = (string)Utility.sink(mTarget.UniqueID, Utility.MethodType.Post, 0, 0, Utility.DataType.Str);
                m.DB_Option_Action = "Update";
                ser.ModuleExecute(m);
                Response.Redirect("Index.aspx");
                Response.End();

            }
        }
    }
}